package com.chen.pfm.entity;

import com.chen.pfm.utils.AccountDBUtil;
import com.chen.pfm.utils.ClassifyDBUtil;
import com.chen.pfm.utils.DateUtils;
import ohos.aafwk.ability.DataAbilityRemoteException;
import ohos.app.Context;

import java.util.ArrayList;
import java.util.List;

public class ChartData {

    String name;
    double data = 0;
    int type = -1;

    public ChartData() {
    }

    @Override
    public String toString() {
        return "ChartData{" +
                "name='" + name + '\'' +
                ", data=" + data +
                '}';
    }

    public ChartData(String name, double data, int type) {
        this.name = name;
        this.data = data;
        this.type = type;
    }

    public ChartData(String name, double data) {
        this.name = name;
        this.data = data;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getData() {
        return data;
    }

    public void setData(double data) {
        this.data = data;
    }


    public static Object[][] getTransferData(List<ChartData> list) {
        int size = list.size();
        if (size == 0) {
            return null;
        }
        Object[][] objects = new Object[list.size()][2];
        for (int i = 0; i < size; i++) {
            String cname = list.get(i).name;
            Double money = list.get(i).data;
            objects[i][0] = cname;
            objects[i][1] = money;
        }
        return objects;
    }


    public static Object[] getPastSevenDaysData(Context context, int type1) {
        Object[] data = new Object[7];
        //得到过去七天的时间
        String[] pastSevenDate = DateUtils.getPastSevenDate();
        //对每一个时间都进行查询，有则返回，无则返回0.0
        for (int i = 0; i < 7; i++) {
            try {
                double v = AccountDBUtil.statisticsMoneyByArtimeAndtype1(context, pastSevenDate[i], type1);
                data[i] = v;
            } catch (DataAbilityRemoteException e) {
                e.printStackTrace();
            }
        }

        return data;
    }
    public static Object[] getY_axisDataByYearMonth(Context context, int type1,String yearmonth) {
        //得到的时间的X轴
        String[] x_axisByMonth = DateUtils.getX_axisByMonth(yearmonth);
        int size=x_axisByMonth.length;
        Object[] data = new Object[size];

        //对每一个时间都进行查询，有则返回，无则返回0.0
        for (int i = 0; i < size; i++) {
            try {
                double v = AccountDBUtil.statisticsMoneyByArtimeAndtype1(context, x_axisByMonth[i], type1);
                data[i] = v;
            } catch (DataAbilityRemoteException e) {
                e.printStackTrace();
            }
        }

        return data;
    }

    public static Object[] getY_axisDataByYear(Context context, int type1,String year) {
        //得到的时间的X轴
        String[] x_axisByYear = DateUtils.getX_axisByYear(year);
        int size=x_axisByYear.length;
        Object[] data = new Object[size];

        //对每一个时间都进行查询，有则返回，无则返回0.0
        for (int i = 0; i < size; i++) {
            try {
                double v = AccountDBUtil.statisticsMoneyByArtimeAndtype1(context, x_axisByYear[i], type1);
                data[i] = v;
            } catch (DataAbilityRemoteException e) {
                e.printStackTrace();
            }
        }

        return data;
    }
    public static Object[] getCurrentData(Context context, int type1) {

        String[] pastSevenDate = DateUtils.getListMonthStartToCurrentDays();
        int size = pastSevenDate.length;
        Object[] data = new Object[size];
        //对每一个时间都进行查询，有则返回，无则返回0.0
        for (int i = 0; i < size; i++) {
            try {
                double v = AccountDBUtil.statisticsMoneyByArtimeAndtype1(context, pastSevenDate[i], type1);
                data[i] = v;
            } catch (DataAbilityRemoteException e) {
                e.printStackTrace();
            }
        }

        return data;
    }


}
